package iteratorbind.entity;


import iteratorbind.base.BaseMenuComponent;

import java.util.Iterator;

/**
 * 菜单项 对象
 * @author yaojianfeng
 */
public class MenuItemLeaf extends BaseMenuComponent {
    String name;
    String description;
    boolean vegetarian;
    double price;

    public MenuItemLeaf(String name, String description, boolean vegetarian, double price) {
        this.name = name;
        this.description = description;
        this.vegetarian = vegetarian;
        this.price = price;
    }

    @Override
    public String getName() {
        return name;
    }

    @Override
    public String getDescription() {
        return description;
    }

    @Override
    public boolean isVegetarian() {
        return vegetarian;
    }

    @Override
    public double getPrice() {
        return price;
    }

    @Override
    public void print(){
        System.out.println("MenuItem{" +
                "name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", vegetarian=" + vegetarian +
                ", price=" + price +
                '}');
    }

    /**
     * 获取迭代器
     * 子类需要实现这个方法
     * 这意味着对一个组合调用该方法 将会应用于该组合的所有节点
     *
     * @return 迭代器
     */
    @Override
    public Iterator getIterator() {
        return new NullIterator();
    }


    @Override
    public String toString() {
        return "MenuItem{" +
                "name='" + name + '\'' +
                ", description='" + description + '\'' +
                ", vegetarian=" + vegetarian +
                ", price=" + price +
                '}';
    }
}
